package ch.hearc.infrarouge.tests;

import java.io.IOException;
import java.util.List;

import org.jsoup.nodes.Document;

import ch.hearc.infrarouge.models.Forum;
import ch.hearc.infrarouge.models.ForumThread;
import ch.hearc.infrarouge.models.Reply;
import ch.hearc.infrarouge.models.User;
import ch.hearc.infrarouge.preferences.Preferences;
import ch.hearc.infrarouge.tools.ConnectionTools;
import ch.hearc.infrarouge.tools.DebugTools;
import ch.hearc.infrarouge.tools.ParserTools;

public class TestJSoup {

	public static void main(String[] args) {
		// setup the proxy settings
		ConnectionTools.setupProxy();

		try {
			Document doc = ParserTools
					.getDocumentFromURL(Preferences.infrarougeForumMinderURL);

			Forum forum = ParserTools.parseForum(doc);
			List<ForumThread> forumThreads = ParserTools.parseForumThreads(doc,
					forum);
			List<Reply> replies = ParserTools.parseAllThreads(forumThreads);

			showReplies(replies);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static void showReplies(List<Reply> replies) {
		for (Reply reply : replies) {
			User from = reply.getReplyFrom();
			User to = reply.getReplyTo();
			String thread = reply.getThreadMessage().getForumThread()
					.getTitle();

			DebugTools.debugln(from + " -> " + to + " in " + thread);
		}
	}
}
